<?
//inculde即可以使用data数据。本页所有的data数据，倾在controller都处理好
include_once("../../../common/modules/checkA.php");
include_once("../../../../config.php");
include_once("../controller/detail-edit.php");

$event_list = select_lines_all_items($table_Prefix . "event", "nid desc", "", "");

$info=select_one_line_all_items($table_Prefix."event","nid = ".$_REQUEST['nid']);

?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <link href="../css/<? echo $theme_folder ?>/user.css" rel="stylesheet" type="text/css"/>
    <?php include ROOT_PATH_.'/controller/common/modules/head.php'; ?>
    <?php include 'modules/head.php'; ?>

    <!--kindeditor编辑器-->
    <link rel="stylesheet" href="../../keditor/themes/default/default.css"/>
    <script charset="utf-8" src="../../keditor/kindeditor-all.js"></script>
    <script charset="utf-8" src="../../keditor/lang/zh_CN.js"></script>

    <script>
        var editor;
        KindEditor.ready(function (K) {
            editor = K.create('textarea[name="ai_content"]', {
                allowFileManager:true,
                afterBlur: function () { editor.sync(); },
                allowFileManager: true,
                filterMode : false,
            });

            editor.options.filterMode = false;

        });

        KindEditor.ready(function (K) {
            editor2 = K.create('textarea[name="ai_finnsh_content"]', {
                allowFileManager:true,
                afterBlur: function () { editor.sync(); },
                allowFileManager: true,
                filterMode : false,
            });

            editor2.options.filterMode = false;

        });

        KindEditor.ready(function (K) {
            editor3 = K.create('textarea[name="ai_user_notice"]', {
                allowFileManager:true,
                afterBlur: function () { editor.sync(); },
                allowFileManager: true,
                filterMode : false,
            });

            editor3.options.filterMode = false;

        });

        KindEditor.ready(function (K) {
            editor4 = K.create('textarea[name="ai_user_agreement"]', {
                allowFileManager:true,
                afterBlur: function () { editor.sync(); },
                allowFileManager: true,
                filterMode : false,
            });

            editor4.options.filterMode = false;

        });

    </script>
</head>


<body>

<div id="topbar">
    <?php include ROOT_PATH_.'/controller/common/modules/topbar.php'; ?>
</div>

<div id="container" class="<? echo $system_part ?>">

    <div id="maincontent">

        <div id="sidebar">
            <?php include ROOT_PATH_.'/controller/common/modules/sidebar.php'; ?>
        </div>






        <div id="content" class="layui-form">
            <div class="box member-add-box layui-form">
                <h1>活动申请主题</h1>

                <form id="add-employee-form" method="post" action="detail-add-function.php?sys_part=activity" enctype="multipart/form-data" class="layui-form">



                    <fieldset class="layui-elem-field layui-field-title">
                        <legend> 基本资料</legend>
                    </fieldset>

                    <div class="layui-form-item">
                        <label class="layui-form-label">选择模板</label>
                        <div class="layui-input-block">
                            <select name="" lay-search=""  lay-filter="event_nid">
                                <option value="0">无</option>
                                <? for($i=0;$i<count($event_list);$i++){ ?>
                                    <option value="<? echo $event_list[$i]['nid'] ?>"><? echo $event_list[$i]['nid'] ?> : <? echo $event_list[$i]['theme'] ?></option>
                                <? } ?>
                            </select>

                        </div>
                    </div>

                    <? if($_REQUEST['nid']){ ?>
                    <input type="hidden" name="ai_image1" value="<?php echo $info['image1'];?>">
                    <? } ?>
                    <?php include 'mod-images-upload.php'; ?>
                    <div class="layui-form-item">
                        <label class="layui-form-label">活动主题</label>
                        <div class="layui-input-block">
                            <input type="text" name="ai_theme" lay-verify="required" placeholder="请输入活动主题名字" autocomplete="off" class="layui-input" value="<?php echo $info['theme'];?>">
                        </div>
                    </div>


                    <!--    <div class="layui-form-item">-->
                    <!--        <label class="layui-form-label">主办方性质</label>-->
                    <!--        <div class="layui-input-block">-->
                    <!--        	<input type="radio" name="ai_sponsor_type" value="个人" title="个人">-->
                    <!--      		<input type="radio" name="ai_sponsor_type" value="单位" title="单位" checked>-->
                    <!--        </div>-->
                    <!--    </div>-->





                    <div class="layui-form-item">
                        <label class="layui-form-label">Leader</label>
                        <div class="layui-input-block">
                            <select name="ai_employee_id" lay-search="" >
                                <option value="<? echo $info['employee_id']?>"><? echo $leader['nid'] ?> : <? echo $leader['nickname']?></option>
                                <option value="">无</option>
                                <? for($i=0;$i<count($leader_list);$i++){ ?>
                                    <option value="<? echo $leader_list[$i]['nid'] ?>"><? echo $leader_list[$i]['nid'] ?> : <? echo $leader_list[$i]['nickname'] ?></option>
                                <? } ?>
                            </select>

                        </div>
                    </div>


                    <div class="layui-form-item">
                        <label class="layui-form-label">联系电话</label>
                        <div class="layui-input-block">
                            <input type="text" name="ai_phone"  placeholder="请输入Leader联系电话" autocomplete="off" class="layui-input" value="">
                        </div>
                    </div>



                    <div class="layui-form-item">
                        <label class="layui-form-label">价格</label>
                        <div class="layui-input-block">
                            <input type="text" name="ai_price"  placeholder="请输入每人价格" autocomplete="off" class="layui-input" value="<?php echo $info['price'];?>">
                        </div>
                    </div>


                    <div class="layui-form-item">
                        <label class="layui-form-label">活动标签</label>
                        <div class="layui-input-block">
                            <?php foreach($tag_list as $tag){

                                ?>
                                <input type="checkbox"  <?php echo in_array($tag,$info_tag) == true ?  'checked' : '' ?> name="ai_tag[]" value="<?php echo $tag?>" title="<?php echo $tag?>">
                                <?php
                            }
                            ?>
                        </div>
                    </div>



                    <div class="layui-form-item">
                        <label class="layui-form-label">活动团体</label>
                        <div class="layui-input-block">
                            <?php foreach($group_list as $group){

                                ?>
                                <input type="checkbox"  <?php echo in_array($group['name'],$info_group) == true ?  'checked' : '' ?>
                                       name="ai_group_nid[]"
                                       value="<?php echo $group['nid']?>" title="<?php echo $group['name']?>">
                                <?php
                            }
                            ?>
                        </div>
                    </div>


                    <div class="layui-form-item">
                        <label class="layui-form-label">预约报名</label>
                        <div class="layui-input-block">
                                <input type="radio"  name="ai_classtype" value="是" title="是">
                                <input type="radio"  name="ai_classtype" value="否" title="否" checked>
                            <div class="notice">勾选【是】的活动将会专门显示在【预约报名标签内】</div>
                        </div>
                    </div>



                    <div class="layui-form-item">
                        <label class="layui-form-label">活动提供方</label>
                        <div class="layui-input-block">
                            <input type="radio"  name="ai_provider" value="官方" title="官方" checked>
                            <input type="radio"  name="ai_provider" value="第三方" title="第三方"  >
                            <div class="notice">官方活动，走收钱流程；第三方活动，不能收钱。</div>
                        </div>
                    </div>


                    <div class="layui-form-item">
                        <label class="layui-form-label">H5报名</label>
                        <div class="layui-input-block">
                            <input type="radio"  name="ai_h5apply" value="H5报名" title="H5报名" >
                            <input type="radio"  name="ai_h5apply" value="小程序报名" title="小程序报名" checked  >
                            <div class="notice">当活动需要真实资料，敏感资料报名的时候，请选择H5报名</div>
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">H5报名项</label>
                        <div class="layui-input-block">
                            <input type="checkbox"  name="ai_h5apply_item[]" value="姓名" title="姓名">
                            <input type="checkbox"  name="ai_h5apply_item[]" value="性别" title="性别">
                            <input type="checkbox"  name="ai_h5apply_item[]" value="年龄" title="年龄">
                            <input type="checkbox"  name="ai_h5apply_item[]" value="身份证号" title="身份证号">
                            <input type="checkbox"  name="ai_h5apply_item[]" value="所属单位" title="所属单位">
                            <input type="checkbox"  name="ai_h5apply_item[]" value="所属团体" title="所属团体">
                            <input type="checkbox"  name="ai_h5apply_item[]" value="所属队伍名称" title="所属队伍名称">
                            <input type="checkbox"  name="ai_h5apply_item[]" value="备注" title="备注">
                            <div class="notice">H5报名时候，点选的信息，将会展示在H5报名页面</div>
                        </div>
                    </div>



                    <fieldset class="layui-elem-field layui-field-title">
                        <legend> 人员设置</legend>
                    </fieldset>



                    <div class="layui-form-item">
                        <label class="layui-form-label">最少女数</label>
                        <div class="layui-input-block">
                            <input type="text" lay-verify="required" name="ai_female_member"  placeholder="请输入女性人数" autocomplete="off" class="layui-input"
                                   value="<?php echo $info['female_member'];?>" >
                        </div>
                    </div>


                    <div class="layui-form-item">
                        <label class="layui-form-label">最少成局人数</label>
                        <div class="layui-input-block">
                            <input type="text" lay-verify="required" name="ai_min_member"  placeholder="请输入最少成局人数" autocomplete="off" class="layui-input"
                                   value="<?php echo $info['min_member'];?>" >
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">最大成局人数</label>
                        <div class="layui-input-block">
                            <input type="text" lay-verify="required" name="ai_sum_member"  placeholder="请输最大用户数" autocomplete="off" class="layui-input" value="<?php echo $info['sum_member'];?>" >
                        </div>
                    </div>




                    <fieldset class="layui-elem-field layui-field-title">
                        <legend> 时间节点</legend>
                    </fieldset>


                    <div class="layui-form-item">
                        <label class="layui-form-label">报名开始</label>
                        <div class="layui-input-block">

                            <input type="text" name="ai_apply_starttime" id="date" autocomplete="off" class="layui-input"
                                   value=""
                                   onclick="laydate({istime: true, format: 'YYYY-MM-DD hh:mm:ss'})"
                                   class="laydate-icon">
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">报名结束</label>
                        <div class="layui-input-block">

                            <input type="text" name="ai_apply_endtime" id="date" autocomplete="off" class="layui-input"
                                   value=""
                                   onclick="laydate({istime: true, format: 'YYYY-MM-DD hh:mm:ss'})"
                                   class="laydate-icon">
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">活动开始</label>
                        <div class="layui-input-block">
                            <input type="text" name="ai_starttime" id="date" autocomplete="off" class="layui-input"
                                   value=""
                                   onclick="laydate({istime: true, format: 'YYYY-MM-DD hh:mm:ss'})" class="laydate-icon">
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">活动结束</label>
                        <div class="layui-input-block">

                            <input type="text" name="ai_endtime" id="date" autocomplete="off" class="layui-input"
                                   value=""
                                   onclick="laydate({istime: true, format: 'YYYY-MM-DD hh:mm:ss'})"
                                   class="laydate-icon">
                        </div>
                    </div>

                    <fieldset class="layui-elem-field layui-field-title">
                        <legend> 更多信息</legend>
                    </fieldset>
                    <div class="layui-form-item">
                        <label class="layui-form-label">活动地址</label>
                        <div class="layui-input-block">

                            <input type="text"  id="mapAddress"  name="ai_address"  autocomplete="off" class="layui-input" value="<?php echo $info['address'];?>"   class="layui-input">
                        </div>
                    </div>

                    <input type="hidden" name="ai_location" id="mapLocation" autocomplete="off" class="layui-input" value="<?php echo $info['location'];?>"  class="layui-input">


                    <div class="layui-form-item">
                        <label class="layui-form-label">坐标查询</label>
                        <div class="layui-input-block">

                            <div id="panel">
                                <p>输入关键字，将展示相关地点提示，点击提示可定位到该处。</p>
                                <div class="layui-input-inline">
                                    <input class="layui-input" id='mapSearch' type="text" value='' oninput="getSuggestions()">
                                </div>
                                <input id="mapSearchBT" type="button" class="layui-btn layui-btn-normal " style="float: left; margin:0 0 0 10px" value="搜索" onclick="searchByKeyword()" />

                                <ul id="suggestionList">
                                </ul>
                            </div>
                            <br class="clearfloat"/>
                            <div id="container_map"  style=" margin:20px 0 0 0;height: 600px; width:1000px;"></div>
                        </div>
                    </div>


                    <div class="layui-form-item">
                        <label class="layui-form-label">用户须知</label>
                        <div class="layui-input-block">
                            <textarea name="ai_user_notice" style="width:800px;height:400px;visibility:hidden;"><?php echo $info['user_notice']?></textarea><em class="explain"></em>

                        </div>
                    </div>
<!--                    <div class="layui-form-item">-->
<!--                        <label class="layui-form-label">用户协议</label>-->
<!--                        <div class="layui-input-block">-->
<!--                            <textarea name="ai_user_agreement" style="width:800px;height:400px;visibility:hidden;">--><?php //echo $info['user_agreement']?><!--</textarea><em class="explain"></em>-->
<!---->
<!--                        </div>-->
<!--                    </div>-->



                    <div class="layui-form-item">
                        <label class="layui-form-label">活动详情</label>
                        <div class="layui-input-block">
                            <textarea name="ai_content" style="width:800px;height:400px;visibility:hidden;"><?php echo $info['content']?></textarea><em class="explain"></em>

                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">活动结束后详情</label>
                        <div class="layui-input-block">
                            <textarea name="ai_finnsh_content" style="width:800px;height:400px;visibility:hidden;"><?php echo $info['finnsh_content']?></textarea><em class="explain"></em>

                        </div>
                    </div>




                    <?//没有管理员权限，只能看到自己所属的
                    if(in_array("admin",$quanxian)){?>

                        <div class="layui-form-item">
                            <label class="layui-form-label">状态</label>
                            <div class="layui-input-block">
                                <input type="radio" name="ai_status" value="1" title="发布中" <?php if($info['status'] == '1'){ echo 'checked="checked"';}?>>
                                <input type="radio" name="ai_status" value="2" title="未发布" <?php if($info['status'] == '2'){ echo 'checked="checked"';}?>>

                            </div>
                        </div>
                        <?;}
                    else{?>

                        <div class="layui-form-item">
                            <label class="layui-form-label">状态</label>
                            <div class="layui-input-block">
                                <input type="radio" name="ai_status" value="1" title="发布中" <?php if($info['status'] == '1'){ echo 'checked="checked"';}?>>
                                <input type="radio" name="ai_status" value="2" title="未发布" <?php if($info['status'] == '2'){ echo 'checked="checked"';}?>>

                            </div>
                        </div>


                        <!-- 如果需要这个功能，把上面删除，显示这个即可         <input type="hidden" name="ai_status" value="0" title="待审核" >-->
                    <?}?>




                    <div class="layui-form-item">
                        <label class="layui-form-label">活动状态</label>
                        <div class="layui-input-block">
                            <input type="radio" name="ai_event_status" value="0" title="组局中" <?php if($info['event_status'] == '0'){ echo 'checked="checked"';}?>>
                            <input type="radio" name="ai_event_status" value="1" title="成局" <?php if($info['event_status'] == '1'){ echo 'checked="checked"';}?>>
                            <input type="radio" name="ai_event_status" value="2" title="流局" <?php if($info['event_status'] == '2'){ echo 'checked="checked"';}?>>

                        </div>
                    </div>

                    <div class="layui-form-item layui-form-text">
                        <label class="layui-form-label">备注</label>
                        <div class="layui-input-block">
                            <textarea name="ai_remark" placeholder="备注" class="layui-textarea"> <?php echo $info['remark'];?></textarea>
                        </div>
                    </div>


                    <div class="function">
                        <div class="layui-input-block">
                            <button class="layui-btn" lay-submit lay-filter="formMemberAdd" type="submit">立即提交</button>
                            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                        </div>
                    </div>



                </form>
            </div>
            <!--maincontent端點01-->
            <br class="clearfloat"/>
        </div>
        <!--container端點01-->
    </div>
    <script charset="utf-8" src="https://map.qq.com/api/gljs?v=1.exp&libraries=service&key=MJABZ-YGGL5-IBIIN-Q5Z45-FMOI7-VIBGN"></script>

    <script>

        layui.use('form', function(){
            var form = layui.form;

            form.on('select(event_nid)', function(data){

                window.location.href="/controller/extender/event/view/detail-add.php?sys_part=event&nowpageid=1&nid=" + data.value

                // console.log(data.elem); //得到select原始DOM对象
                // console.log(data.value); //得到被选中的值
                // console.log(data.othis); //得到美化后的DOM对象
            });

            //监听提交
            form.on('submit(formMemberAdd)', function(data){
                ai_starttime = data.field.ai_starttime
                ai_endtime = data.field.ai_endtime
                ai_apply_starttime = data.field.ai_apply_starttime
                ai_apply_endtime = data.field.ai_apply_endtime

                if(ai_apply_starttime == ''){
                    alert('请选择活动报名开始时间')
                    return false;
                }
                if(ai_apply_endtime == ''){
                    alert('请选择活动报名结束时间')
                    return false;
                }

                if(ai_starttime == ''){
                    alert('请选择活动开始时间')
                    return false;
                }
                if(ai_endtime == ''){
                    alert('请选择活动结束时间')
                    return false;
                }

                if(ai_starttime > ai_endtime){
                    alert('活动结束时间不能高于活动开始时间')
                    return false;
                }

                if(ai_apply_starttime > ai_apply_endtime ){
                    alert('活动报名结束时间不能高于活动报名开始时间')
                    return false;
                }
                if(ai_apply_endtime > ai_starttime ){
                    alert('活动报名结束时间不能迟于活动开始时间')
                    return false;
                }

                return true;
            });
        });
    </script>

    <script type="text/javascript">
        var map = new TMap.Map('container_map', {
            zoom: 14,
            center: new TMap.LatLng(22.183765,112.304914),
        });
        var suggestionList = [];
        var search = new TMap.service.Search({ pageSize: 10 }); // 新建一个地点搜索类
        var suggest = new TMap.service.Suggestion({
            // 新建一个关键字输入提示类
            pageSize: 10, // 返回结果每页条目数
            region: '恩平', // 限制城市范围
            regionFix: true, // 搜索无结果时是否固定在当前城市
        });
        var markers = new TMap.MultiMarker({
            map: map,
            geometries: [],
        });
        var infoWindowList = Array(10);
        function getSuggestions() {
            // 使用者在搜索框中输入文字时触发
            var suggestionListContainer = document.getElementById('suggestionList');
            suggestionListContainer.innerHTML = '';
            var keyword = document.getElementById('mapSearch').value;
            if (keyword) {
                suggest
                    .getSuggestions({ keyword: keyword, location: map.getCenter() })
                    .then((result) => {
                        // 以当前所输入关键字获取输入提示
                        suggestionListContainer.innerHTML = '';
                        suggestionList = result.data;
                        suggestionList.forEach((item, index) => {
                            suggestionListContainer.innerHTML += `<li><a href="javascript:;" onclick="setSuggestion(${index})">${item.title}<span class="item_info">${item.address}</span></a></li>`;
                        });
                    })
                    .catch((error) => {
                        console.log(error);
                    });
            }
        }

        function setSuggestion(index) {
            // 点击输入提示后，于地图中用点标记绘制该地点，并显示信息窗体，包含其名称、地址等信息
            infoWindowList.forEach((infoWindow) => {
                infoWindow.close();
            });
            infoWindowList.length = 0;
            document.getElementById('mapSearch').value = suggestionList[index].title;
            document.getElementById('suggestionList').innerHTML = '';
            markers.setGeometries([]);
            markers.updateGeometries([
                {
                    id: '0', // 点标注数据数组
                    position: suggestionList[index].location,
                },
            ]);
            var infoWindow = new TMap.InfoWindow({
                map: map,
                position: suggestionList[index].location,
                content: `<h3>${suggestionList[index].title}</h3><p>地址：${suggestionList[index].address}</p>`,
                offset: { x: 0, y: -50 },
            });
            infoWindowList.push(infoWindow);
            map.setCenter(suggestionList[index].location);

            _location = suggestionList[index].location.lat+','+suggestionList[index].location.lng
            _address = suggestionList[index].title

            $('#mapLocation').val(_location)
            $('#mapAddress').val(_address)

            markers.on('click', (e) => {
                infoWindowList[Number(e.geometry.id)].open();
            });
        }

        function searchByKeyword() {
            // 关键字搜索功能
            infoWindowList.forEach((infoWindow) => {
                infoWindow.close();
            });
            infoWindowList.length = 0;
            markers.setGeometries([]);
            search
                .searchRectangle({
                    keyword: document.getElementById('mapSearch').value,
                    bounds: map.getBounds(),
                })
                .then((result) => {
                    result.data.forEach((item, index) => {
                        var geometries = markers.getGeometries();
                        var infoWindow = new TMap.InfoWindow({
                            map: map,
                            position: item.location,
                            content: `<h3>${item.title}</h3><p>地址：${item.address}</p><p>电话：${item.tel}</p>`,
                            offset: { x: 0, y: -50 },
                        });
                        infoWindow.close();
                        infoWindowList[index] = infoWindow;
                        geometries.push({
                            id: String(index),
                            position: item.location,
                        });
                        markers.updateGeometries(geometries);
                        markers.on('click', (e) => {
                            infoWindowList[Number(e.geometry.id)].open();
                        });
                    });
                });
        }
    </script>

    <?php include ROOT_PATH_ . "/controller/common/modules/footer.php"; ?> </body>
</html>
